import net.badimon.five3D.display.DynamicText;
import net.badimon.five3D.display.Scene;
import net.badimon.five3D.display.Sprite;
import net.badimon.five3D.typography.HelveticaBold;
import net.badimon.five3D.utils.Drawing;

class Application {

	function Application(clip:MovieClip) {
		
		// We create the scene and save the link to the root.
		var scene:Scene = new Scene(clip);
		var root:Sprite = scene.getRoot();

		// We center the root.
		root._x = 300;
		root._y = 200;

		// We create a new sprite named "sign" into the root and draw a rounded rectangle inside.
		var sign:Sprite = root.createSprite("sign", 0);
		Drawing.roundedPlace(sign, -150, -150, 300, 300, 20, 0x000000);

		// We create a new sprite named "star" into "sign", draw a star inside and place it.
		var star:Sprite = sign.createSprite("star", 0);
		Drawing.star(star, 20, 60, 50, 0, 0xD7006C);
		star._x = 120;
		star._y = -80;

		// We attribute a function to the "onEnterFrame" event of the "star" that defines a rotation.
		star.onEnterFrame = function():Void {
			this._rotationz++;
		};

		// We create a new dynamic text named "hi" into "sign", modify its properties and place it.
		var hi:DynamicText = sign.createDynamicText("hi", 1);
		hi._typography = HelveticaBold;
		hi._size = 50;
		hi._color = 0xFFFFFF;
		hi._text = "Hi!";
		hi._x = 88;
		hi._y = -110;

		// We create a new dynamic text named "world" into "sign", modify its properties and place it.
		var world:DynamicText = sign.createDynamicText("world", 2);
		world._typography = HelveticaBold;
		world._size = 80;
		world._color = 0x666666;
		world._text = "World";
		world._x = -112;
		world._y = -34;

		// We attribute a random value to the rotations on the X, Y and Z axes of the "sign".
		sign._rotationx = Math.random() * 100 - 50;
		sign._rotationy = Math.random() * 100 - 50;
		sign._rotationz = Math.random() * 100 - 50;

		// We attribute a function to the "onPress" event of the "sign" that defines other random rotations.
		sign.onPress = function():Void {
			this._rotationx = Math.random() * 100 - 50;
			this._rotationy = Math.random() * 100 - 50;
			this._rotationz = Math.random() * 100 - 50;
		};
	}
}